<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% String path=pageContext.getServletContext().getContextPath(); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>门诊退费</title>
	<link rel="stylesheet" type="text/css" href="<%=path %>/eazyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=path %>/eazyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="<%=path %>/eazyui/demo/demo.css">
	<script type="text/javascript" src="<%=path %>/eazyui/jquery.min.js"></script>
	<script type="text/javascript" src="<%=path %>/eazyui/jquery.easyui.min.js"></script>
	<script>
	
	function ckformatterNum(value,row,index){
		var str = '<input type="text" id="ck'+index+'" style="width:80%" class="num"/>';
		return str;	
	}
	function cmformatterNum(value,row,index){
		var str = '<input type="text" id="cm'+index+'" style="width:80%" class="num" />';
		return str;	
	}
	function wmformatterNum(value,row,index){
		var str = '<input type="text" id="wm'+index+'" style="width:80%" class="num" />';
		return str;	
	}
	function ckformatterBtn(value,row,index){
		var str = '<a href="#" class="easyui-linkbutton"  style="width:50%;height:32px;margin:25px auto;" onclick="ckRefund(&quot;'+row.ck_id+'&quot;,&quot;'+row.ck_price+'&quot;,'+index+')" >退费</a>';
		return str;
	}
	function cmformatterBtn(value,row,index){
		var str = '<a href="#" class="easyui-linkbutton"  style="width:50%;height:32px;margin:25px auto;" onclick="cmRefund(&quot;'+row.cm_id+'&quot;,&quot;'+row.cm_price+'&quot;,'+index+')" >退费</a>';
		return str;
	}
	function wmformatterBtn(value,row,index){
		var str = '<a href="#" class="easyui-linkbutton"  style="width:50%;height:32px;margin:25px auto;" onclick="wmRefund(&quot;'+row.wm_id+'&quot;,&quot;'+row.wm_price+'&quot;,'+index+')" >退费</a>';
		return str;
	}
	
	function findPatientInfo(){
		var patient_name = document.getElementById("name").value;
		var patient_idcard = document.getElementById("number").value;
		$.post("<%=path %>/refund/getPatient",{patient_name:patient_name,patient_idcard:patient_idcard},function(data,textStatus){
				if(textStatus=="success"){
				console.log(data);
				$.each(data,function(index,result){
					result.patient_sex =result.patient_sex==0?"女":"男";
				})
				if(eval(data).length>0){
					$('#patientInfo').show();
					$('#patientDg').datagrid('resize');
					$('#patientDg').datagrid('loadData',{'total':eval(data).length,rows:data});
				}else{
					$('#patientInfo').hide();
				}
				}
			})
		$.post("<%=path %>/refund/getCmPrescription",{},function(data,textStatus){
			if(textStatus=="success"){
				console.log(data);
				if(eval(data).length>0){
					//$('#cmInfoDiv').css("display","block");
					$('#cmInfoDiv').show();
					$('#cmInfo').datagrid('resize');
					$('#cmInfo').datagrid('loadData',{'total':eval(data).length,rows:data});
				}else{
					//$('#cmInfoDiv').css("display","none");
					$('#cmInfoDiv').hide();
					}
				}
			})
		$.post("<%=path %>/refund/getWmPrescription",{},function(data,textStatus){
			if(textStatus=="success"){
				console.log(data);
				if(eval(data).length>0){
					//$('#wmInfoDiv').css("display","block");
					$('#wmInfoDiv').show();
					$('#wmInfo').datagrid('resize');
					$('#wmInfo').datagrid('loadData',{'total':eval(data).length,rows:data});
				}else{
					//$('#wmInfoDiv').css("display","none");
					$('#wmInfoDiv').hide();
					}
				}
			})

		$.post("<%=path %>/refund/getCkPrescription",{},function(data,textStatus){
			if(textStatus=="success"){
				console.log(data);
				if(eval(data).length>0){
					//$('#ckInfoDiv').css("display","block");
					$('#ckInfoDiv').show();
					$('#ckInfo').datagrid('resize');
					$('#ckInfo').datagrid('loadData',{'total':eval(data).length,rows:data});
				}else{
					//$('#ckInfoDiv').css("display","none");
					$('#ckInfoDiv').hide();
					}
				}
			})

	}

	
	function ckRefund(ck_id,ck_price,index){
		var a = $("#ck"+index).val();
		var ck_amount_refund = ck_price*a;
		var ls_data = new Date();
		$.post("<%=path %>/refund/ckRefund",{ck_amount_refund:ck_amount_refund,ck_id:ck_id,ls_data:ls_data},function(data,textStatus){
			if(textStatus=="success"){
				console.log(data);
				alert("退费成功");
				findPatientInfo();
				//$('#ckInfo').datagrid('updateRow',{
					//index:index,
					//row:{
					//	ck_amount_refund:ck_amount_refund,
					//}
				//});
			}
		});
	}
	function cmRefund(cm_id,cm_price,index){
		var b = $("#cm"+index).val();
		var cm_amount_refund = cm_price*b;
		var ls_data = new Date();
		$.post("<%=path %>/refund/cmRefund",{cm_amount_refund:cm_amount_refund,cm_id:cm_id,ls_data:ls_data},function(data,textStatus){
			if(textStatus=="success"){
				console.log(data);
				alert("退费成功");
				findPatientInfo();
				//$('#cmInfo').datagrid('updateRow',{
					//index:index,
					//row:{
					//	cm_amount_refund:cm_amount_refund,
					//}
				//});
			}
		});
	}
	function wmRefund(wm_id,wm_price,index){
		var c = $("#wm"+index).val();
		var wm_amount_refund = wm_price*c;
		var ls_data = new Date();
		$.post("<%=path %>/refund/wmRefund",{wm_amount_refund:wm_amount_refund,wm_id:wm_id,ls_data:ls_data},function(data,textStatus){
			if(textStatus=="success"){
				console.log(data);
				alert("退费成功");
				findPatientInfo();
				//$('#wmInfo').datagrid('updateRow',{
					//index:index,
					//row:{
						//wm_amount_refund:wm_amount_refund,
					//}
				//});
			}
		});
	}
	</script>
</head>
<body>
	<div>
		<form id="findFeeList" method="post" style="margin:0px;display:inline;">
			<div>
				<input class="form-control" type="hidden" id="guahao"  name='guahao'>
				<label for="supplementid">身份证号码</label>
				<input class="form-control"  type='text' id="number"  name='number'>  
				<label for="supplementid">姓名</label>
				<input class="form-control"  type='text' id="name"  name='name'>  
				<a href="#" class="easyui-linkbutton"  style="width:10%;height:25px;margin:25px auto;" onclick="findPatientInfo()" >查询</a>
			</div>
		</form>
		<br>
		<form id="allInfo" method="post">
			<div id="patientInfo" style="margin:0;display:none;" >
			<table id="patientDg" class="easyui-datagrid" style="width:100%" >
    		<thead>
				<tr>
					<th field="patient_name" width="25%">姓名</th>
					<th field='patient_age'" width="25%">年龄</th>
					<th field='patient_sex'" width="25%">性别</th>
					<th field='patient_idcard'" width="25%">身份证号</th>					
				</tr>				
    		</thead>	
    		<tbody id="pbody">
    			
    		</tbody>
    		</table>
   			</div>
			<br>	   
			<!-- 药品信息 --> 
			<div id="wmInfoDiv" style="display:none;">
			<table id="wmInfo" class="easyui-datagrid" >
				<thead>
				<tr>
					<th field="wm_name" width="20%">西药名称</th>
					<th field="wm_id" width="20%">药品代码</th>				
					<th field="wm_price" width="10%">单价</th>
					<th field="wm_num" width="10%">数量</th>
					<th field="wm_amount" width="10%">合计金额</th>
					<th field='wm_action1' style="width:10%;" data-options="formatter:wmformatterNum">退费数量</th>
					<th field="wm_amount_refund" width="10%">合计退费</th>
					<th field='wm_action2' style="width:10%;" data-options="formatter:wmformatterBtn" />
				</tr>			
    			</thead>	
				<tbody id="wmbody">

				</tbody>	
			</table>
			</div>
			<br><br><br>
			<div id="cmInfoDiv" style="display:none;">
			<table id="cmInfo" class="easyui-datagrid">
				<thead>
				<tr>
					<th field="cm_name" width="20%">中药名称</th>
					<th field="cm_id" width="20%">药品代码</th>					
					<th field="cm_price" width="10%">单价</th>
					<th field="cm_num" width="10%">数量</th>
					<th field="cm_amount" width="10%">合计金额</th>
					<th field='cm_action1' style="width:10%;" data-options="formatter:cmformatterNum">退费数量</th>
					<th field="cm_amount_refund" width="10%">合计退费</th>
					<th field='cm_action2' style="width:10%;" data-options="formatter:cmformatterBtn" />
				</tr>				
    			</thead>	
				<tbody id="cmbody">
					
				</tbody>	
			</table>
			</div>
			<br><br><br>
			<!-- 项目信息 --> 
			<div id="ckInfoDiv" style="display:none;">
			<table id="ckInfo" class="easyui-datagrid">
				<thead>
				<tr>
					<th field="ck_name" width="20%">项目名称</th>
					<th field="ck_id" width="20%">项目编号</th>			
					<th field="ck_price" width="10%">单价</th>
					<th field="ck_num" width="10%">数量</th>
					<th field="ck_amount" width="10%">合计金额</th>
					<th field='ck_action1' style="width:10%;" data-options="formatter:ckformatterNum">退费数量</th>
					<th field="ck_amount_refund" width="10%">合计退费</th>
					<th field='ck_action2' style="width:10%;" data-options="formatter:ckformatterBtn" />
				</tr>				
    			</thead>	
				<tbody id="ckbody">
    				  
				</tbody>	
            </table>
            </div>
            <br><br><br>
		</form>
	</div>
</body>
</html>